<template>
	<view class="">
		<!-- <view class="set-item">
			<view class="">
				头像
			</view>
			<view class="set-item-img" @click="chooseTheImg">
				<image style="	width: 50px;
				height: 50px; border-radius: 50%;" :src="userInfo.userIcon" mode=""></image>
				<image src="../../static/img/my/yousanjiao.png" mode=""></image>
			</view>
		</view>
		<view class="set-item" @click="toChangeNickname">
			<view class="">
				昵称
			</view>
			<view class="set-item-img">
				<text>{{userInfo.nickName}}</text>
				<image src="../../static/img/my/yousanjiao.png" mode=""></image>
			</view>
		</view> -->
		<view class="set-item" @click="toupdataPassd">
			<view class="">
				修改密码
			</view>
			<view class="set-item-img">
				<image src="../../static/img/index/ic_next_black.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="set-item" @click="upadetaApp">
			<view class="">
				检查更新
			</view>
			<view class="set-item-img">
				<text>{{curVersion}}</text>
				<image src="../../static/img/index/ic_next_black.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="">
			<button type="default" class="button" @click="logOut">退出登录</button>

		</view>
	</view>
</template>

<script>
	import checkVersion from '@/pages/lq-upgrade/checkVersion.js'
	const api = require('../../config/api');
	const util = require('../../utils/util');
	import number from "../../utils/number.js";
	export default {
		data() {
			return {
				curVersion: '',
				curVersionCode: '',
				number: number, //声明number属性并赋值为引入的number模块
				userInfo: {},
				totalAmt: 0,
				balance: 0,
				phone: '18205405955',
				changeInform: {
					"isVoiceBroadcast": "",
					"nickName": "",
					"userImg": ""
				}
			}
		},
		onShow() {
			// this.upadetaApp();
			//#ifdef APP-PLUS
			this.getApp();
			//#endif
		},
		onLoad() {
			// this.getuserInfo();
		},
		methods: {
			toupdataPassd(){
				uni.navigateTo({
					url: '/pages/ForgotPassword/ForgotPassword'
				});
			},
			
			// 版本更新
			getApp() {
				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
					this.curVersion = wgtinfo.version; //应用版本名称
					this.curVersionCode = wgtinfo.versionCode; //应用版本号
				});
			},
			// 版本更新
			upadetaApp() {
				uni.showLoading({
					title: '正在检查更新'
				})
				this.upgrade()
			},
			async upgrade() {
				let platform = uni.getSystemInfoSync().platform //手机平台
				let PHtype
				if (platform === 'android') {
					PHtype = "1"
			
				}
				//IOS无法在线升级提示到商店下载
				else {
					PHtype = "0"
				}
				const serverVersion = await util.request(api.appVersionUrl + '/' + '3' + '/' + PHtype, {
			
				}, 'POST');
				// console.log(serverVersion);
				if (serverVersion.code == 0) {
					let name = serverVersion.data.versionName; //新版本名称
					let code = serverVersion.data.versionNo; //新版本号（数字）
					let content = serverVersion.data.versionDesc; //更新内容
					let url = serverVersion.data.downloadUrl; //app下载链接，（演示请换成真正在下载链接）
					let forceUpdate; // 是否强制更新，初始化为undefined
			
					// 判断是否需要强制更新  
					if (serverVersion.data.upgrade == 1) {
						forceUpdate = true;
					} else {
						forceUpdate = false;
					}
					const upgradeResult = checkVersion({
						name, //最新版本名称
						code, //最新版本号
						content, //更新内容
						url, //下载链接
						forceUpdate //是否强制升级           
					})
					if (upgradeResult === false) {
						uni.hideLoading()
			
						setTimeout(() => {
							// uni.showToast({
							// 	title: '已是最新版本',
							// 	icon: 'none'
							// });
						}, 30)
					} else {
						uni.hideLoading()
					}
				} else {
					// uni.showToast({
					// 	title: "检查更新失败",
					// 	icon: "none"
					// })
				}
			},
			logOut() {
				uni.removeStorageSync("token");
				uni.reLaunch({
					url: '/pages/login/login'
				});
			},
		}

	}
</script>

<style>
	.set-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #fff;
		border-bottom: 0.5px solid #F4F6FA;
		position: relative;
		padding: 15px;
	}

	.set-item-img {
		display: flex;
		align-items: center;
	}

	.set-item-img image {
		width: 10px;
		height: 20px;
		margin-left: 10px;
	}

/* 	.button {
		width: 210px;
		height: 40px;
		background-color: #2C5FE5 !important;
		color: #fff !important;
		line-height: 40px;
		margin-top: 30px;
		border-radius: 20px;
		font-size: 14px;
	} */
	.button {
		
		width: 225px;
		height: 44px;
		margin: 10px auto;
		text-align: center;
		/* padding-right: 15px; */
		color: #fff !important;
		font-size: 14px;
		line-height: 44px;
		background-color: #6A9FFB !important;
		border-radius: 5px;
		margin-top: 20px;
	}
</style>